import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class OpenThirdParty extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('如何打开第三方链接'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: ()=>_launchURL(),
              child: Text('打开浏览器'),
            ),
            RaisedButton(
              onPressed: ()=>_openMap(),
              child: Text('打开地图'),
            ),
          ],
        ),
      ),
    );
  }
  _launchURL() async {
    const url = 'http://www.baidu.com';
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
  _openMap() async{
    //Android
    const url = 'geo:52.32,4.917'; //App提供者提供的schema
    if(await canLaunch(url)){
      await launch(url);
    }else{
      //ios
      const url = 'http://maps.apple.com/?ll=52.32,4.917';
      if(await canLaunch(url)){
        await launch(url);
      }else{
        throw 'Could not launch $url';
      }
    }
  }
}
